<template>
  <div class="container">
    <el-dialog
      :title="dialog.dialogType === 'edit' ? '修改管理员' : '创建管理员'"
      :visible.sync="dialog.centerDialogVisible"
      width="550px"
      center
      :lock-scroll="true"
      @open="getOpen"
      @closed="hideDialog"
    >
      <el-form
        :model="formData"
        :rules="rules"
        ref="formData"
        label-width="120px"
        label-position="left"
      >
        <el-form-item label="用户名：" prop="name">
          <el-input
            :disabled="dialog.dialogType === 'edit'"
            v-model="formData.name"
            placeholder="请输入用户名"
          />
        </el-form-item>
        <el-form-item
          v-if="dialog.dialogType === 'edit' ? false : true"
          label="密码："
          prop="password"
        >
          <el-input v-model="formData.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="管理员名称：" prop="nickname">
          <el-input
            v-model="formData.nickname"
            placeholder="请输入管理员名称"
          />
        </el-form-item>
        <el-form-item label="管理员角色：" prop="roleId">
          <el-select
            v-model="formData.roleVal"
            @change="getOptionId(formData.roleVal)"
            placeholder="请选择管理员角色"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="账号类型：" prop="acc_type">
          <el-select
            v-model="formData.acc_type"
            placeholder="请选择账号类型"
            @change="changequery(formData.acc_type)"
          >
            <el-option
              v-for="item in acc_typeoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="
            formData.acc_type == 2 ||
              formData.acc_type == 3 ||
              formData.acc_type == 5 ||
              formData.acc_type == 9
          "
          :label="formData.accTypeName"
          prop="supplierId"
        >
          <el-select
            style="width: 100%"
            v-model="formData.acc_name"
            filterable
            remote
            center
            reserve-keyword
            placeholder="请输入关键字"
            :remote-method="insideRemoteMethods"
            :loading="insides.loading"
            @change="getOptionIds(formData.acc_name)"
          >
            <el-option
              v-for="item in insides.options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="
            isSupplier || isFinance || superSupplier || superFinance || house
          "
          :label="formData.accTypeName"
        >
          <el-select
            style="width: 70%"
            v-model="supplierListId"
            filterable
            remote
            center
            reserve-keyword
            placeholder="请输入关键字"
            :remote-method="insideRemoteMethods"
            :loading="inside.loading"
          >
            <el-option
              v-for="item in inside.options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          <el-button type="primary" @click="addSupplierList">添加</el-button>
        </el-form-item>
        <div
          class="tabList"
          v-if="
            (isSupplier && tags.length > 0) ||
              (isFinance && tags.length > 0) ||
              (superSupplier && tags.length > 0) ||
              (superFinance && tags.length > 0) ||
              (house && tags.length > 0)
          "
        >
          <el-tag
            v-for="tag in tags"
            @close="close(tag)"
            :key="tag.name"
            closable
            type="info"
            >{{ tag.name }}</el-tag
          >
        </div>
        <el-form-item label="手机号：" prop="phone">
          <el-input v-model="formData.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="邮箱：">
          <el-input v-model="formData.email" placeholder="请输入邮箱" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideDialog">取 消</el-button>
        <el-button type="primary" @click="comitDialog">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getList } from "@/api/putStorage/putStotageList";
import {
  addAdminInfo,
  editAdminInfo,
  findAdminInfo,
  getAreaList,
  selectBuyerList,
  selectSupplierList,
  getRegionList
} from "@/api/permission/adminlist";
import { roleList } from "@/api/permission/roleList";
import { selectRdcDataNew } from "@/api/permission/adminlist";

import { supplierList } from "@/api/supplier/supplierList";
import { storeList } from "@/api/store/storeList";
import { selectSupplierData } from "@/api/supplier/supplierList"; //供应商
export default {
  props: {
    dialog: Object
  },
  data() {
    return {
      rules: {
        name: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
          { min: 6, max: 20, message: "密码长度6-20字符", trigger: "blur" }
        ],
        nickname: [
          { required: true, message: "管理员名称不能为空", trigger: "blur" }
        ],
        roleId: [
          { required: true, message: "管理员角色不能为空", trigger: "blur" }
        ],
        supplierId: [
          { required: true, message: "供应商或店铺不能为空", trigger: "blur" }
        ],
        acc_type: [
          { required: true, message: "请选择账号类型", trigger: "blur" }
        ],
        phone: [{ required: true, message: "手机号不能为空", trigger: "blur" }]
      },
      formData: {
        name: "",
        password: "",
        nickname: "",
        roleName: "",
        roleId: "",
        roleVal: "",
        acc_type: 0,
        supplierId: "",
        phone: "",
        acc_name: "",
        email: "",
        buyer: "",
        buyer_code: ""
      },

      options: [],
      acc_typeoptions: [
        {
          value: 0,
          label: "平台账号"
        },
        {
          value: 1,
          label: "供应商账号"
        },
        {
          value: 10,
          label: "门店账号"
        },
        {
          value: 3,
          label: "采购账号"
        },
        {
          value: 4,
          label: "财务账号"
        },
        {
          value: 5,
          label: " 商超采购员账号"
        },
        {
          value: 6,
          label: "商超供应商账号"
        },
        {
          value: 7,
          label: "商超财务账号"
        },
        {
          value: 8,
          label: "挑单账号"
        },

        {
          value: 2,
          label: "店铺账号"
        }
      ],
      supplierListId: "",
      isSupplier: false,
      isFinance: false,
      superSupplier: false,
      acc_type: false,
      superFinance: false,
      house: false,
      inside: {
        innerVisible: false,
        options: [],
        value: "",
        list: [],
        loading: false,
        id: "",
        buy_order_id: ""
      },
      insides: {
        innerVisible: false,
        options: [],
        value: "",
        list: [],
        loading: false,
        id: "",
        buy_order_id: ""
      },
      tags: []
    };
  },
  created() {
    // this.getRole();
  },
  methods: {
    //获取角色列表
    getRole() {
      let data = {
        search: "",
        page: 1,
        limit: 100
      };
      roleList(data).then(res => {
        if (res.code == 0) {
          res.data.data.forEach(res => {
            this.options.push({
              label: res.role_name,
              value: res.role_id
            });
          });
        }
      });
    },
    getOpen() {
      this.getRole();
      if (this.dialog.dialogType == "edit") {
        let data = {
          admin_id: this.dialog.admin_id
        };
        findAdminInfo(data).then(res => {
          if (res.code == 0) {
            this.formData = {
              name: res.data.admin_info.username,
              nickname: res.data.admin_info.nickname,
              roleId: res.data.admin_info.role_id,
              roleVal: res.data.admin_info.role_name,
              acc_type: res.data.admin_info.acc_type,
              acc_name:
                res.data.admin_info.acc_name.length != 0
                  ? res.data.admin_info.acc_type == 9
                    ? res.data.admin_info.acc_name[0].company_name
                    : res.data.admin_info.acc_name[0].name +
                      "/" +
                      res.data.admin_info.acc_name[0].code
                  : res.data.admin_info.buyer +
                    "/" +
                    res.data.admin_info.buyer_code,
              supplierId: res.data.admin_info.acc_type_id,
              phone: res.data.admin_info.phone,
              email: res.data.admin_info.email,
              buyer: res.data.admin_info.buyer,
              buyer_code: res.data.admin_info.buyer_code
            };

            this.formData.acc_name =
              this.formData.acc_name == "/" ? "" : this.formData.acc_name;
            if (res.data.admin_info.acc_type == 1) {
              res.data.admin_info.acc_name.forEach(result => {
                this.tags.push({
                  id: result.id,
                  name: result.name
                });
              });
              let data = {
                page: 1,
                limit: 50
              };

              //获取初始化供应商列表
              this.isSupplier = true;
              supplierList(data).then(res => {
                this.inside.options = res.data.data.map(item => {
                  return { value: `${item.id}`, label: `${item.name}` };
                });
              });
            } else if (res.data.admin_info.acc_type == 4) {
              res.data.admin_info.acc_name.forEach(result => {
                this.tags.push({
                  id: result.code,
                  name: result.name
                });
              });
              let data = {
                page: 1,
                limit: 50
              };
              getAreaList(data).then(res => {
                this.inside.options = res.data.listdata.map(item => {
                  return {
                    value: `${item.code}`,
                    label: `${item.name}`
                  };
                });
              });
            } else if (res.data.admin_info.acc_type == 6) {
              res.data.admin_info.acc_name.forEach(result => {
                this.tags.push({
                  id: result.id,
                  name: result.name
                });
              });
              let data = {
                page: 1,
                limit: 50
              };
              selectSupplierData(data).then(res => {
                this.inside.options = res.data.paginate.data.map(item => {
                  return {
                    value: `${item.id}`,
                    label: `${item.supplier_name}`
                  };
                });
              });
            } else if (res.data.admin_info.acc_type == 7) {
              res.data.admin_info.acc_name.forEach(result => {
                this.tags.push({
                  id: result.id,
                  name: result.name
                });
              });
              let data = {
                page: 1,
                limit: 50
              };
              getRegionList(data).then(res => {
                this.inside.options = res.data.paginate.data.map(item => {
                  return {
                    value: `${item.id}`,
                    label: `${item.name}`
                  };
                });
              });
            } else if (res.data.admin_info.acc_type == 8) {
              res.data.admin_info.acc_name.forEach(result => {
                this.tags.push({
                  id: result.d_code,
                  name: result.d_name
                });
              });
              let data = {
                page: 1,
                limit: 50
              };
              selectRdcDataNew(data).then(res => {
                this.inside.options = res.data.paginate.data.map(item => {
                  return {
                    value: `${item.d_code}`,
                    label: `${item.d_name}`
                  };
                });
              });
            }
            switch (res.data.admin_info.acc_type) {
              case 0:
                this.formData.accTypeName = "平台账号：";
                break;
              case 1:
                this.formData.accTypeName = "供应商账号：";
                break;
              case 2:
                this.formData.accTypeName = "店铺账号：";
                break;
              case 3:
                this.formData.accTypeName = "采购账号：";
                break;
              case 4:
                this.formData.accTypeName = "区域名称：";
                break;
              case 5:
                this.formData.accTypeName = "商超采购员：";
                break;
              case 6:
                this.formData.accTypeName = "商超供应商：";
                break;
              case 7:
                this.formData.accTypeName = "商超区域名称:";
                break;
              case 8:
                this.formData.accTypeName = "配送中心:";
                break;
            }
            this.isSupplier = res.data.admin_info.acc_type == 1 ? true : false;
            this.isFinance = res.data.admin_info.acc_type == 4 ? true : false;
            this.superSupplier =
              res.data.admin_info.acc_type == 6 ? true : false;
            this.superFinance =
              res.data.admin_info.acc_type == 7 ? true : false;
            this.house = res.data.admin_info.acc_type == 8 ? true : false;
          }
        });
      } else {
        this.formData = {
          name: "",
          password: "",
          nickname: "",
          roleName: "",
          roleId: "",
          roleVal: "",
          acc_type: 0,
          supplierId: "",
          phone: "",
          acc_name: "",
          email: "",
          buyer: "",
          buyer_code: ""
        };
      }
    },
    //获取供应商或者店铺数据
    getSupplierLists(query) {
      let data = {
        name: query,
        page: 1,
        limit: 100
      };
      this.inside.loading = true;
      if (this.formData.acc_type == 1) {
        supplierList(data).then(res => {
          this.inside.list = res.data.data.map(item => {
            return { value: `${item.id}`, label: `${item.name}` };
          });
          this.inside.options = this.inside.list.filter(item => {
            this.inside.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 2) {
        storeList(data).then(res => {
          this.insides.list = res.data.data.map(item => {
            return { value: `${item.id}`, label: `${item.name}` };
          });
          this.insides.options = this.insides.list.filter(item => {
            this.insides.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 3) {
        let datas = {
          key: query,
          page: 1,
          limit: 100
        };
        getList(datas).then(res => {
          this.insides.options = res.data.map(item => {
            return {
              value: `${item.code}`,
              label: `${item.name}/${item.code}`,
              name: `${item.name}`
            };
          });
          // this.insides.options = this.insides.list.filter((item) => {
          //   this.insides.loading = false;
          //   return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          // });
        });
      } else if (this.formData.acc_type == 4) {
        let datas = {
          key: query,
          page: 1,
          limit: 100
        };
        getAreaList(datas).then(res => {
          this.inside.list = res.data.listdata.map(item => {
            return {
              value: `${item.code}`,
              label: `${item.name}`
            };
          });
          this.inside.options = this.inside.list.filter(item => {
            this.inside.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 5) {
        let datas = {
          key: query,
          page: 1,
          limit: 100
        };
        getList(datas).then(res => {
          this.insides.list = res.data.map(item => {
            return {
              value: `${item.code}`,
              label: `${item.name}/${item.code}`,
              name: `${item.name}`
            };
          });
          this.insides.options = this.insides.list.filter(item => {
            this.insides.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 6) {
        selectSupplierData(data).then(res => {
          this.inside.list = res.data.paginate.data.map(item => {
            return { value: `${item.id}`, label: `${item.supplier_name}` };
          });
          this.inside.options = this.inside.list.filter(item => {
            this.inside.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 7) {
        getRegionList(data).then(res => {
          this.inside.list = res.data.paginate.data.map(item => {
            return { value: `${item.id}`, label: `${item.name}` };
          });
          this.inside.options = this.inside.list.filter(item => {
            this.inside.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 8) {
        selectRdcDataNew(data).then(res => {
          this.inside.list = res.data.paginate.data.map(item => {
            return {
              value: `${item.d_code}`,
              label: `${item.d_name}`
            };
          });
          this.inside.options = this.inside.list.filter(item => {
            this.inside.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else if (this.formData.acc_type == 9) {
        selectRdcDataNew(data).then(res => {
          this.inside.list = res.data.paginate.data.map(item => {
            return {
              value: `${item.d_code}`,
              label: `${item.d_name}`
            };
          });
          this.inside.options = this.inside.list.filter(item => {
            this.inside.loading = false;
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      }
    },
    //添加
    addSupplierList() {
      let arr = this.tags.filter(res => {
        return res.id == this.supplierListId;
      });
      if (this.isSupplier) {
        if (arr.length == 0) {
          if (this.tags.length >= 50) {
            this.$message({
              message: "添加供应商已超过50个",
              type: "warning"
            });
          } else {
            let supplier = this.inside.options.filter(res => {
              return res.value == this.supplierListId;
            });
            this.tags.push({
              name: supplier[0].label,
              id: supplier[0].value
            });
          }
        } else {
          this.$message({
            message: "该供应商已添加",
            type: "warning"
          });
        }
      } else if (this.isFinance) {
        if (arr.length == 0) {
          if (this.tags.length >= 20) {
            this.$message({
              message: "添加区域已超过20个",
              type: "warning"
            });
          } else {
            let supplier = this.inside.options.filter(res => {
              return res.value == this.supplierListId;
            });
            this.tags.push({
              name: supplier[0].label,
              id: supplier[0].value
            });
          }
        } else {
          this.$message({
            message: "该区域已添加",
            type: "warning"
          });
        }
      } else if (this.superSupplier) {
        if (arr.length == 0) {
          if (this.tags.length >= 50) {
            this.$message({
              message: "添加商超供应商已超过50个",
              type: "warning"
            });
          } else {
            let supplier = this.inside.options.filter(res => {
              return res.value == this.supplierListId;
            });
            this.tags.push({
              name: supplier[0].label,
              id: supplier[0].value
            });
          }
        } else {
          this.$message({
            message: "该商超供应商已添加",
            type: "warning"
          });
        }
      } else if (this.superFinance) {
        if (arr.length == 0) {
          if (this.tags.length >= 20) {
            this.$message({
              message: "添加商超区域已超过20个",
              type: "warning"
            });
          } else {
            let supplier = this.inside.options.filter(res => {
              return res.value == this.supplierListId;
            });
            this.tags.push({
              name: supplier[0].label,
              id: supplier[0].value
            });
          }
        } else {
          this.$message({
            message: "该商超区域已添加",
            type: "warning"
          });
        }
      } else if (this.house) {
        if (arr.length == 0) {
          if (this.tags.length >= 20) {
            this.$message({
              message: "添加配送中心已超过20个",
              type: "warning"
            });
          } else {
            let supplier = this.inside.options.filter(res => {
              return res.value == this.supplierListId;
            });
            this.tags.push({
              name: supplier[0].label,
              id: supplier[0].value
            });
          }
        } else {
          this.$message({
            message: "该配送中心已添加",
            type: "warning"
          });
        }
      }
    },
    // 搜索供应商或者店铺数据
    insideRemoteMethods(query) {
      if (query !== "") {
        this.getSupplierLists(query);
      } else {
        this.insides.options = [];
        this.inside.options = [];
      }
    },
    //获取角色ID
    getOptionId(val) {
      this.formData.roleId = val;
    },
    //获取供应商或者店铺ID
    getOptionIds(val) {
      this.formData.supplierId = val;
      if (this.formData.acc_type == 3) {
        let arr = this.insides.options.filter(res => {
          return res.value == val;
        });
        this.formData.buyer = arr[0].name;
        this.formData.buyer_code = arr[0].value;
      } else if (this.formData.acc_type == 5) {
        let arr = this.insides.options.filter(res => {
          return res.value == val;
        });
        this.formData.buyer = arr[0].name;
        this.formData.buyer_code = arr[0].value;
      }
    },
    //隐藏表单
    hideDialog() {
      this.tags = [];
      this.inside = {
        innerVisible: false,
        options: [],
        value: "",
        list: [],
        loading: false,
        id: "",
        buy_order_id: ""
      };
      this.insides = {
        innerVisible: false,
        options: [],
        value: "",
        list: [],
        loading: false,
        id: "",
        buy_order_id: ""
      };
      this.options = [];
      this.supplierListId = "";
      this.isSupplier = false;
      this.isFinance = false;
      this.superSupplier = false;
      this.superFinance = false;
      this.house = false;
      this.tags = [];
      this.formData = {
        name: "",
        password: "",
        nickname: "",
        roleName: "",
        roleId: "",
        roleVal: "",
        acc_type: 0,
        supplierId: "",
        phone: "",
        acc_name: "",
        email: "",
        buyer: "",
        buyer_code: ""
      };
      this.dialog.centerDialogVisible = false;
    },
    //提交表单
    comitDialog() {
      this.$refs["formData"].validate(valid => {
        if (valid) {
          let data = {
            username: this.formData.name,
            password: this.formData.password,
            nickname: this.formData.nickname,
            phone: this.formData.phone,
            email: this.formData.email,
            acc_type: this.formData.acc_type,
            // acc_type_id:
            //   this.formData.acc_type > 0 && this.formData.acc_type <= 2
            //     ? this.formData.supplierId
            //     : "",
            role_id: this.formData.roleId,
            buyer: this.formData.buyer,
            buyer_code: this.formData.buyer_code
          };
          let arr = [];
          switch (this.formData.acc_type) {
            case 1:
              this.tags.forEach(res => {
                arr.push(res.id);
              });
              data.acc_type_id = arr.join(",");
              break;
            case 2:
              data.acc_type_id = this.formData.supplierId;
              break;
            case 3:
              data.acc_type_id = this.formData.supplierId;
              break;
            case 4:
              this.tags.forEach(res => {
                arr.push(res.id);
              });
              data.acc_type_id = arr.join(",");
              break;
            case 5:
              data.acc_type_id = this.formData.supplierId;
              break;
            case 6:
              this.tags.forEach(res => {
                arr.push(res.id);
              });
              data.acc_type_id = arr.join(",");
              break;
            case 7:
              this.tags.forEach(res => {
                arr.push(res.id);
              });
              data.acc_type_id = arr.join(",");
              break;
            case 8:
              this.tags.forEach(res => {
                arr.push(res.id);
              });
              data.acc_type_id = arr.join(",");
              break;
            case 9:
              data.acc_type_id = this.formData.supplierId;
              break;
          }
          // console.log(data)
          // return false
          if (this.dialog.dialogType === "edit") {
            data.admin_id = this.dialog.admin_id;
            editAdminInfo(data)
              .then(res => {
                if (res.code == 0) {
                  this.$message({
                    message: res.msg,
                    type: "success"
                  });
                  this.hideDialog();
                  this.$emit("upData");
                } else {
                  this.$message({
                    message: res.msg,
                    type: "error"
                  });
                }
              })
              .catch(err => {
                console.log(err);
              });
          } else {
            data.password = this.formData.password;
            addAdminInfo(data)
              .then(res => {
                if (res.code == 0) {
                  this.$message({
                    message: res.msg,
                    type: "success"
                  });
                  this.hideDialog();
                  this.$emit("upData");
                } else {
                  this.$message({
                    message: res.msg,
                    type: "error"
                  });
                }
              })
              .catch(err => {
                console.log(err);
              });
          }
        } else {
          return false;
        }
      });
    },
    //移除供应商
    close(scope) {
      let item = null;
      this.tags.forEach((res, index) => {
        if (res.id == scope.id) {
          item = index;
        }
      });
      this.tags.splice(item, 1);
    },
    changequery(val) {
      switch (val) {
        case 0:
          this.formData.accTypeName = "平台账号：";
          break;
        case 1:
          this.formData.accTypeName = "供应商账号：";
          break;
        case 2:
          this.formData.accTypeName = "店铺账号：";
          break;
        case 3:
          this.formData.accTypeName = "采购账号：";
          break;
        case 4:
          this.formData.accTypeName = "区域名称：";
          break;
        case 5:
          this.formData.accTypeName = "商超采购员：";
          break;
        case 6:
          this.formData.accTypeName = "商超供应商：";
          break;
        case 7:
          this.formData.accTypeName = "商超区域名称:";
          break;
        case 8:
          this.formData.accTypeName = "配送中心:";
          break;
      }

      this.tags = [];
      this.isSupplier = false;
      this.isFinance = false;
      this.superSupplier = false;
      this.superFinance = false;
      this.house = false;

      this.formData.supplierId = "";
      this.formData.acc_name = "";
      this.formData.buyer = "";
      this.formData.buyer_code = "";
      this.supplierListId = "";
      this.insides = {
        innerVisible: false,
        options: [],
        value: "",
        list: [],
        loading: false,
        id: "",
        buy_order_id: ""
      };
      this.inside = {
        innerVisible: false,
        options: [],
        value: "",
        list: [],
        loading: false,
        id: "",
        buy_order_id: ""
      };
      let data = {
        page: 1,
        limit: 50
      };
      if (val == 1) {
        //获取初始化供应商列表
        this.isSupplier = true;
        this.isFinance = false;
        this.superSupplier = false;
        this.superFinance = false;
        this.house = false;

        supplierList(data).then(res => {
          this.inside.options = res.data.data.map(item => {
            return { value: `${item.id}`, label: `${item.name}` };
          });
        });
      } else if (val == 2) {
        //获取初始化店铺列表
        this.isSupplier = false;
        this.isFinance = false;
        this.superSupplier = false;
        this.superFinance = false;
        this.house = false;

        storeList(data).then(res => {
          this.insides.options = res.data.data.map(item => {
            return { value: `${item.id}`, label: `${item.name}` };
          });
        });
      } else if (val == 3) {
        //获取初始化采购列表
        this.isSupplier = false;
        this.isFinance = false;
        this.superSupplier = false;
        this.superFinance = false;
        this.house = false;

        getList(data).then(res => {
          this.insides.options = res.data.map(item => {
            return {
              value: `${item.code}`,
              label: `${item.name}/${item.code}`,
              name: `${item.name}`
            };
          });
        });
      } else if (val == 4) {
        //获取初始化区域列表
        this.isSupplier = false;
        this.isFinance = true;
        this.superSupplier = false;
        this.superFinance = false;
        this.house = false;

        getAreaList(data).then(res => {
          this.inside.options = res.data.listdata.map(item => {
            return {
              value: `${item.code}`,
              label: `${item.name}`
            };
          });
        });
      } else if (val == 5) {
        //获取初始化商超采购员列表

        this.isSupplier = false;
        this.isFinance = false;
        this.superSupplier = false;
        this.superFinance = false;
        this.house = false;

        getList(data).then(res => {
          this.insides.options = res.data.map(item => {
            return {
              value: `${item.code}`,
              label: `${item.name}/${item.code}`,
              name: `${item.name}`
            };
          });
        });
      } else if (val == 6) {
        //获取初始化商超供应商列表
        this.isSupplier = false;
        this.isFinance = false;
        this.superSupplier = true;
        this.superFinance = false;
        this.house = false;

        selectSupplierData(data).then(res => {
          this.inside.options = res.data.paginate.data.map(item => {
            return { value: `${item.id}`, label: `${item.supplier_name}` };
          });
        });
      } else if (val == 7) {
        //获取初始化商超区域列表
        this.isSupplier = false;
        this.isFinance = false;
        this.superSupplier = false;
        this.superFinance = true;
        this.house = false;

        getRegionList(data).then(res => {
          this.inside.options = res.data.paginate.data.map(item => {
            return {
              value: `${item.id}`,
              label: `${item.name}`
            };
          });
        });
      } else if (val == 8) {
        //获取挑单账号列表
        this.isSupplier = false;
        this.isFinance = false;
        this.superSupplier = false;
        this.superFinance = false;
        this.house = true;
        selectRdcDataNew(data).then(res => {
          this.inside.options = res.data.paginate.data.map(item => {
            return {
              value: `${item.d_code}`,
              label: `${item.d_name}`
            };
          });
        });
      }
    }
  }
};
</script>
<style scoped>
.tab {
  display: flex;
}
.tab .el-form-item {
  flex: 1;
}
.tabList {
  padding: 10px;
  border: 1px solid #eee;
  margin-bottom: 5px;
}
.tabList span {
  margin-left: 5px;
  margin-bottom: 5px;
}
</style>
